package com.elock.intf.controller;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.elock.base.core.Filter;
import com.elock.base.core.Page;
import com.elock.base.core.Pageable;
import com.elock.base.core.controller.BaseController;
import com.elock.base.core.controller.ResultMsg;
import com.elock.base.core.util.ConvertUtil;
import com.elock.intf.service.IntfTerminalMessageEventService;
import com.elock.service.CompanyInfoService;

/**
 * Controller - 事件监控列表
 * @author 仁德
 */
@Controller("intfMessageEventController")
@RequestMapping("/intf/message_event")
public class MessageEventController extends BaseController {

	@Resource(name = "intfTerminalMessageEventServiceImpl")
	private IntfTerminalMessageEventService intfTerminalMessageEventService;
	@Resource(name = "companyInfoServiceImpl")
	private CompanyInfoService companyInfoService;

	/**
	 * 列表数据
	 */
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	public @ResponseBody ResultMsg list_data(String companycode, String terminalNum,
			String elockNum, String saleOrgSn, String startTime, String endTime,
			Pageable pageable, ModelMap model) {

		if (ConvertUtil.isEmpty(companycode)) {
			return error("请传入企业编号");
		}
		if (!companyInfoService.exists(Filter.eq("company_code", companycode))) {
			return error("不存在企业编号为[" + companycode + "]的企业");
		}

		Object[] args = { companycode,
				terminalNum,
				elockNum,
				saleOrgSn,
				startTime,
				endTime };
		Page<Map<String, Object>> pageMap = intfTerminalMessageEventService
				.findPage(pageable, args);

		return success().addObjX(pageMap);
	}
}
